#include <stdio.h>
#include <stdlib.h>
#include "slist.h"

Node list;

bool cmp_int(Node *list, void *value)
{
	if (!list || !value) {
		printf("E: func:%s parameter error\n", __func__);
		return false;
	}

	if (*(int *)(list->data) == *(int *)value) {
		return true;
	} else {
		return false;
	}
}

main()
{
	int i = 0;
	int *value = NULL;
	int _value = 5;
	Pnode elem = NULL;

	if (init_slist(&list)) {
		printf("E: init slist error\n");
	}

	printf("length of the list: %d\n", len_of_slist(&list));
	
	if (is_slist_empty(&list) == true) {
		printf("list is empty \n", len_of_slist(&list));
	} else {
		printf("list is not empty \n", len_of_slist(&list));
	}

	for (; i < MAX_SIZE; i++) {
		elem = (Pnode)malloc(sizeof(Node));
		elem->data = (int *)malloc(sizeof(int));
		*((int *)elem->data) = i;
		printf("insert the %ds elem\n", i);
		if (-1 == insert_elem(&list, i + 1, elem)) {
			printf("insert the %ds elem error\n", i);
			exit(1);
		}
	}

	printf("length of the list: %d\n", len_of_slist(&list));
	
	if (is_slist_empty(&list) == true) {
		printf("list is empty \n", len_of_slist(&list));
	} else {
		printf("list is not empty \n", len_of_slist(&list));
	}

	get_elem(&list, 5, (void *)&value);
	printf("value: %d\n", *(int *)value);

	locate_elem(&list, value, cmp_int, &_value);
	printf("value 5 is located in %d\n", _value);
	
	destroy_slist(&list);
	return 0;
}
